1. Field of the Invention
The present invention generally relates to multi-threaded processing and more specifically to emitting coherent output from multiple threads for printf.
2. Description of the Related Art
During execution of a program by a single-threaded processor, data generated by the program may be output during run-time. The data that is output may be used for debugging of the program, for output of either interim or final computed data, or for other informational purposes.
The standard C language library defines the printf( ) function as a mechanism for emitting formatted data-dependent output from a program at runtime. The printf( ) function accepts a string of text to output, within which may be found optional format specifiers. These are tokens which represent locations within the string where data generated by the program during run-time should be substituted. Format specifiers comprise a % symbol followed by optional formatting codes, and ending with a character indicating the type of data to substitute for each token. Conventional single threaded processing outputs coherent data that is formatted for display when the printf( ) function is executed by the single-threaded processor.
The output of coherent data from multiple threads simultaneously presents a more complex problem, as the multiple threads need access to a single output stream. If multiple threads output without any co-ordination, the resulting display of the text strings and data may be an unintelligible mix of characters generated by the multiple threads as the printf( ) functions are executed.
In addition to the problem encountered with multiple threads accessing a single output stream, the actual formatting of the data for display as specified by the formatting codes presents an additional problem. Specifically, the many conditional branches required to satisfy the complex formatting capabilities of the printf( ) function are ill-suited to a single-instruction multiple-thread (SIMT) execution model, resulting in considerable execution divergence and poor efficiency. Essentially, execution of the multiple threads is serialized for the printf( ) function. Each thread traverses the printf string, substituting data for each token as the token is encountered after reading the data from memory and formatting the data according to the formatting codes.
Accordingly, what is needed in the art is an improved system and method for emitting coherent output from multiple threads for the printf( ) function. Additionally, a technique for maintaining parallel (not divergent) execution of the threads for the printf( ) function is desired to improve run-time performance.